let url = ''
if (process.env.NODE_ENV === 'development') {
	// url = "http://121.42.143.36:1888/"
	// url = 'https://api.xuyuanguodu.art/';
	// url = 'http://47.104.13.65/';
	// url = 'http://121.42.143.36:10001/';
	// url = 'https://api.fejgj3.cn/';
	// url = 'https://api.fejiu2.cn/';
	url = 'http://langchao.art/';
	
	
} else {
	//url = window.location.origin+'/'
	// url = 'http://47.104.13.65/';
	// url = 'https://api.fejgj3.cn/';
	// url = 'https://api.fejiu2.cn/';
	url = 'http://langchao.art/';
	// url = 'http://121.42.143.36:10001/';
}

export const baseUrl = url;
let whiteArr = []
export function http(url, data, method = 'GET') {
	return new Promise((resolve, reject) => {
		uni.request({
			url: baseUrl + url,
			data,
			header: {
				'content-type': 'application/x-www-form-urlencoded',
				'token': uni.getStorageSync('token') || ''
			},
			method,
			success: (res) => {
				if (res.statusCode == 200) {
					if (res.data.code == 1) {
						resolve(res.data.data)
					} else if (res.data.code == 0) {
						uni.showToast({
							title: res.data.msg,
							icon: 'none'
						})
						reject(res.data.msg)
					} else if (res.data.code == 401) {
						uni.reLaunch({
							url: '/pages/login/index'
						})
						reject(res.data.msg);
					}
					else if (res.data.code == 403) {
						uni.showToast({
							title: '请先实名认证!',
							icon: 'none'
						})
						setTimeout(()=>{
							uni.navigateTo({
								url: '/pages/my/realAuth'
							})
						},500)
						reject(res.data.msg);
					}else if(res.data.code == 1001){
					console.log('33')
					uni.showToast({
						title: '请先开通会员',
						icon: 'none'
					})
					setTimeout(()=>{
						uni.navigateTo({
							url: '/pages/my/premium'
						})
					},2000)
					reject(res.data.msg);
				}
				}else {
					uni.showToast({
						title: "活动火爆进行中,请稍后重试1!",
						icon: 'none'
					})
				}
			},
			fail: (res) => {
				uni.showToast({
					title: '无法连接到数据库',
					icon: 'none'
				})
			},
			complete: () => {

			}
		});
	})
}

